var initUserMoneyInfoBean;

var getUserMoneyInfoBeanFromOpenPage = function(){
	var usermoneyinfoBean = {};
	
	usermoneyinfoBean.id = jQuery('#idEditor').val();
	
	usermoneyinfoBean.userId = jQuery('#userIdEditor').val();
	if(!usermoneyinfoBean.userId){
		$.ligerDialog.error("请输入用户编号!");
		return null;
	}
	
	usermoneyinfoBean.money = jQuery('#moneyEditor').val();
	if(!usermoneyinfoBean.money){
		$.ligerDialog.error("请输入充值金额!");
		return null;
	}
	
	usermoneyinfoBean.qd = jQuery('#qdEditor').val();
	if(!usermoneyinfoBean.qd){
		$.ligerDialog.error("请输入渠道类型!");
		return null;
	}
	
	usermoneyinfoBean.qdUser = jQuery('#qdUserEditor').val();
	if(!usermoneyinfoBean.qdUser){
		$.ligerDialog.error("请输入渠道账户!");
		return null;
	}
	
	usermoneyinfoBean.state = jQuery('#stateEditor').val();
	if(!usermoneyinfoBean.state){
		$.ligerDialog.error("请输入充值状态!");
		return null;
	}
	
	usermoneyinfoBean.registTime = jQuery('#registTimeEditor').val();
	if(!usermoneyinfoBean.registTime){
		$.ligerDialog.error("请输入创建时间!");
		return null;
	}else{
		usermoneyinfoBean.registTime += ':00';
		usermoneyinfoBean.registTime =  new Date(Date.parse(usermoneyinfoBean.registTime.replace(/-/g,   "/")));
	}
	
	usermoneyinfoBean.configTime = jQuery('#configTimeEditor').val();
	if(usermoneyinfoBean.configTime){
		usermoneyinfoBean.configTime += ':00';
		usermoneyinfoBean.configTime =  new Date(Date.parse(usermoneyinfoBean.configTime.replace(/-/g,   "/")));
	}
	return usermoneyinfoBean;
};

var initUserMoneyInfoEditPage = function(){
	jQuery("#registTimeEditor").ligerDateEditor({
		format:'yyyy-MM-dd hh:mm',
		showTime:true,
	});
	
	jQuery("#configTimeEditor").ligerDateEditor({
		format:'yyyy-MM-dd hh:mm',
		showTime:true,
	});
	
	jQuery('#ligerQd').ligerComboBox({
		data:qdRenderData,
		valueField:'value',
		textField:'text',
		initValue:qdRenderData[0].value,
		valueFieldID:'qdEditor'
	});
	jQuery('#ligerState').ligerComboBox({
		data:payStateRenderData,
		valueField:'value',
		textField:'text',
		initValue:payStateRenderData[0].value,
		valueFieldID:'stateEditor'
	});
};

var bindUserMoneyInfoUpdateButtom = function(){
	jQuery('#updateEdit').unbind('click').click(function(){
		var usermoneyinfoBean = getUserMoneyInfoBeanFromOpenPage();
		if(null != usermoneyinfoBean){
			doSaveUserMoneyInfos([usermoneyinfoBean]);
		}
	});
};
var bindUserMoneyInfoResetButtom = function(){
	jQuery('#resetEdit').unbind('click').click(function(){
		if(!initUserMoneyInfoBean){
			jQuery("#userIdEditor").val('');
			jQuery("#moneyEditor").val('');
			jQuery("#qdEditor").val('');
			jQuery("#qdUserEditor").val('');
			jQuery("#stateEditor").val('');
			jQuery("#registTimeEditor").val('');
			jQuery("#configTimeEditor").val('');
		}else{
			if(!initUserMoneyInfoBean.userId){
				jQuery("#userIdEditor").val('');
			}else{
				jQuery("#userIdEditor").val(initUserMoneyInfoBean.userId);
			}
			if(!initUserMoneyInfoBean.money){
				jQuery("#moneyEditor").val('');
			}else{
				jQuery("#moneyEditor").val(initUserMoneyInfoBean.money);
			}
			if(!initUserMoneyInfoBean.qd){
				jQuery("#qdEditor").val('');
			}else{
				jQuery("#qdEditor").val(initUserMoneyInfoBean.qd);
			}
			if(!initUserMoneyInfoBean.qdUser){
				jQuery("#qdUserEditor").val('');
			}else{
				jQuery("#qdUserEditor").val(initUserMoneyInfoBean.qdUser);
			}
			if(!initUserMoneyInfoBean.state){
				jQuery("#stateEditor").val('');
			}else{
				jQuery("#stateEditor").val(initUserMoneyInfoBean.state);
			}
			if(!initUserMoneyInfoBean.registTime){
				jQuery("#registTimeEditor").val('');
			}else{
				var temp = new Date(initUserMoneyInfoBean.registTime);
				jQuery("#registTimeEditor").val(temp.formatLiger());
			}
			if(!initUserMoneyInfoBean.configTime){
				jQuery("#configTimeEditor").val('');
			}else{
				var temp = new Date(initUserMoneyInfoBean.configTime);
				jQuery("#configTimeEditor").val(temp.formatLiger());
			}
		}
	});
};

jQuery(function(){
	initUserMoneyInfoEditPage();
	bindUserMoneyInfoUpdateButtom();
	bindUserMoneyInfoResetButtom();
});